package com.example.demo.controller;

import com.example.demo.model.Collection;
import com.example.demo.model.Student;
import com.example.demo.model.User;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class UseController {

  @Resource(name = "getUser1")
    private User user;
/*    @Resource(name = "getUser3")
    private User user1;*/
@Resource(name = "getUser3")
private  User user3;

@Resource(name="getUser4")
private User user4;

@Resource(name="getUser5")
private User user5;

@Autowired
Student student;
@Value("${demo.key1}")
    String name;
    @Autowired
    ConfigurableApplicationContext context;


    @Autowired
    Collection collection;
    @RequestMapping("/01")
    public void fun(){
        System.out.println("第一个对象"+user);
        System.out.println("第二个对象"+context.getBean("getUser1"));

    }

    @RequestMapping("/02")
    public void fun1(){
        System.out.println("属性注入获取到的对象"+user3);
        System.out.println("conText获取到的对象为"+context.getBean("getUser3"));

    }

    @RequestMapping("/03")
    public void fun2(){
        System.out.println("属性注入获取到的对象"+user4);
        System.out.println("conText获取到的对象为"+context.getBean("getUser4"));

    }


    @RequestMapping("/04")
    public void fun3(){
        System.out.println("属性注入获取到的对象"+user5);
        System.out.println("conText获取到的对象为"+context.getBean("getUser5"));
        System.out.println(name);
        Student student1 = new Student();
        System.out.println(student);
        System.out.println(student1);
        System.out.println(collection.map);
        // 第一种方法，foreach keySet
        for (String key : collection.map.keySet()) {
            System.out.print(key + "-" + collection.map.get(key) + "\t");
        }


    }

}
